<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%divided_payments_order}}".
 *
 * @property integer $id
 * @property integer $custom_id
 * @property integer $car_id
 * @property integer $status
 * @property string $serialize_data
 *
 * @property Car $car
 * @property Custom $custom
 * @property DividedPaymentsOrderLog[] $dividedPaymentsOrderLogs
 */
class DividedPaymentsOrder extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%divided_payments_order}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['custom_id', 'car_id', 'serialize_data'], 'required'],
            [['custom_id', 'car_id', 'status'], 'integer'],
            [['serialize_data'], 'string'],
            [['custom_id'], 'unique'],
            [['car_id'], 'exist', 'skipOnError' => true, 'targetClass' => Car::className(), 'targetAttribute' => ['car_id' => 'id']],
            [['custom_id'], 'exist', 'skipOnError' => true, 'targetClass' => Custom::className(), 'targetAttribute' => ['custom_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'custom_id' => 'Custom ID',
            'car_id' => 'Car ID',
            'status' => 'Status',
            'serialize_data' => 'Serialize Data',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCar()
    {
        return $this->hasOne(Car::className(), ['id' => 'car_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCustom()
    {
        return $this->hasOne(Custom::className(), ['id' => 'custom_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDividedPaymentsOrderLogs()
    {
        return $this->hasMany(DividedPaymentsOrderLog::className(), ['divided_payments_order_id' => 'id']);
    }
}
